//
//  BRHeartBeatTask.m
//  ZhuShou
//
//  Created by Dejun Liu on 15/11/20.
//  Copyright © 2015年 jw. All rights reserved.
//

#import "BRHeartBeatTask.h"

@interface BRHeartBeatTask()

@end

@implementation BRHeartBeatTask

JW_SINGLETON_IMPL(BRHeartBeatTask)

- (void)start
{
    [self performSelectorInBackground:@selector(runloop) withObject:nil];
}

- (void)runloop
{
    [NSTimer scheduledTimerWithTimeInterval:10
                                     target:self
                                   selector:@selector(sendMessage)
                                   userInfo:nil
                                    repeats:YES];
    [[NSRunLoop currentRunLoop]run];
}

- (void)sendMessage
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params hs_setSafeValue:@"heartbeat" forKey:@"type"];
    [params hs_setSafeValue:@"email" forKey:@"name"];
    [params hs_setSafeValue:@"cheneylew@163.com" forKey:@"value"];
//    @weakify(self);
    [BRServiceCenter BRServiceCenterUPDWithAction:@"underlying" CMD:[BRCommand CommandHeartBeat] params:params response:^(BRMessageResponseType type, NSInteger retryCount, id responseObj) {
        if (responseObj) {
//            @strongify(self);
            BRUDPResponse *response = responseObj;
            if ([response.state isEqualToString:@"0000"]) {

            }else
            {
                
            }
        }
    }];
}

@end
